import { ref } from "vue";

// 预览 编辑  新增的三个传递属性，免得每个页面重复定义
export const useDialog = () => {
  const visible = ref<boolean>(false);
  const id = ref<IDType>();
  const type = ref<DialogType>("view");
  const updateData = ref<any>(); // 部分场景可能没有详情接口，需要从列表取数据
  const handleView = (item: any, key: string = "id") => {
    type.value = "view";
    updateData.value = item;
    id.value = item[key];
    visible.value = true;
  };
  const handleEdit = (item: any, key: string = "id") => {
    updateData.value = item;
    type.value = "edit";
    id.value = item[key];
    visible.value = true;
  };
  const handleCreate = (item: any, key: string = "id") => {
    type.value = "create";
    id.value = undefined;
    visible.value = true;
  };
  return {
    visible,
    id,
    type,
    handleView,
    handleEdit,
    handleCreate,
  };
};
